import random
import time
import types
import hashlib

def getNoncestr():
    chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
    retstr=''
    for i in range(0,16):
        tmprdm=random.randint(0, len(chars))
        retstr=retstr.join(chars[tmprdm])
    return retstr

def getTime():
    return int(time.time())

def getSHA1sign(msgdir):
    retdir={}
    string1=""
    if type(msgdir) is types.DictType:
        for i in msgdir: 
            retdir[i.lower()]=msgdir[i]
    retdir=sorted(retdir.items(),key=lambda retdir:retdir[0])
    for i in retdir:
        string1=string1+i[0]+"="+i[1]+'&'
    string1=string1[0:len(string1)-1]
#     print hashlib.sha1(string1).hexdigest()
    return hashlib.sha1(string1).hexdigest()